$(document).ready(function() {
    $.getJSON('/backend/get-data?data=product-category-sale-monthly', function(data) {
        column_chart('category-sale-monthly', 'Category Monthly Sales', data.labels, data.series)
    })

    var section_id = 'category-sale-share'
    var title = 'Category Sale Share'
    $('a[href="#'+section_id+'"]').click(function(e) {
        if(! $(this).data('shown')) {
            $(this).data('shown', true)
            $.getJSON('/backend/get-data?data=product-'+section_id, function(items) {
                pie_chart(section_id, title, items)
            })
        }
    })

    function lazy_load(section_id, title) {
        $('a[href="#'+section_id+'"]').click(function(e) {
            if(! $(this).data('shown')) {
                $(this).data('shown', true)
                $.getJSON('/backend/get-data?data=product-'+section_id, function(data) {
                    column_chart(section_id, title, data.labels, data.series)
                })
            }
        })
    }

    lazy_load('popular', 'Most Popular Products')
    lazy_load('obscure', 'Most Unpopular Products')
})
